from functools import reduce
from operator import xor
import socket
import json

def connect_car(message: str):
    with socket.socket() as s:
        s.connect(("chassis.local", 8080))
        s.send(message.encode("ascii"))
        return json.loads(s.recv(1024).decode("ascii"))["port"]

with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
    s.bind(("", 0))
    port = s.getsockname()[1]
    port = connect_car(json.dumps({"port": port, "type": "remote"}))
    addr = ("chassis.local", port)
    print(addr)
    s.connect(addr)
    while True:
        l, r = map(int, input().split())
        data = [0xBB, 0xBB, 1, 4, 0, l, r, 0]
        data.append(reduce(xor, data))
        s.send(b"".join(map(lambda x: x.to_bytes(1), data)))
